package com.ssms.controller;

import com.ssms.commons.Result;
import com.ssms.commons.TablePage;
import com.ssms.model.Clazz;
import com.ssms.service.ClazzService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/clazz")
public class ClazzController {

    @Resource
    private ClazzService clazzService;

    @RequestMapping()
    public String clazz() {
        return "clazz";
    }

    @RequestMapping("list")
    @ResponseBody
    public TablePage list(TablePage tablePage, @RequestParam(value = "subjectId") Integer subjectId) {
        return clazzService.search(tablePage, subjectId);
    }

    @RequestMapping("all/{subjectId}")
    @ResponseBody
    public Result all(@PathVariable("subjectId") Integer subjectId) {
        return clazzService.all(subjectId);
    }

    @RequestMapping("add")
    @ResponseBody
    public Result add(Clazz clazz) {
        return clazzService.save(clazz);
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(Clazz clazz) {
        return clazzService.update(clazz);
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result delete(Integer id) {
        return clazzService.delete(id);
    }

}
